package lab3;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author joser93
 */
public class ConectorODBC {

    Connection con;

    public ConectorODBC(String nomMaquina, String puerto, String SID, String user, String pass) throws SQLException {
        DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
        con = DriverManager.getConnection("jdbc:oracle:thin:@" + nomMaquina + ":" + puerto + ":" + SID, user, pass);

        System.out.println(nomMaquina);
        System.out.println(puerto);
        System.out.println(SID);
        System.out.println(user);
        System.out.println(pass);
        if (con != null) {
            System.out.println("Conectado");
        }
    }

    public ConectorODBC(String nomMaquina, String puerto, String SID, String user, String pass, String rol) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        String driverName = "oracle.jdbc.driver.OracleDriver";
        Class.forName(driverName).newInstance();
        String nameForConnect = user+" as "+rol;
        String url = "jdbc:oracle:thin:@1"+nomMaquina+":"+puerto+":ORCL";
        con = DriverManager.getConnection(url, nameForConnect, pass);
        if (con != null) {
            System.out.println("Conectado");
        }
    }

    public static void main(String[] args) {
        try {
            try {
                ConectorODBC c = new ConectorODBC("localhost", "1521", "DB11C", "nuevo", "1234", "sysdba");
            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
                Logger.getLogger(ConectorODBC.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (SQLException  ex) {
            System.err.println(ex.getMessage());
        }
    }

}
